What is the difference between these two find algorithms? [migrated]

Posted by Joe on Super User See other posts from Super User or by Joe
Published on 2012-09-09T02:26:14Z Indexed on 2012/09/09 3:40 UTC
Read the original article Hit count: 398

Filed under:
|
|

I have these two find algorithm which look the same to me. Can anyone help me out why they are actually different?

Find ( x ) :
    if x.parent = x then 
        return x
    else 
        return Find ( x.parent )

vs

Find ( x ) :
    if x.parent = x then 
        return x
    else 
        x.parent <- Find(x.parent)
        return x.parent 

I interpret the first one as

 int i = 0;    
 return i++;

while the second one as

int i = 0;
int tmp = i++;
return tmp

which are exactly the same to me.

© Super User or respective owner

Related posts about java

Related posts about source-code